﻿using Projet_IMA.Base;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace Projet_IMA.Habillage.Material
{
    public abstract class MaterialBase
    {
        protected Scene3D scene;
        protected TextureBump Bump;

        public Boolean AsDiffus { get; set; }
        public Boolean AsSpecular { get; set; }

        public float DiffusIntensity { get; set; }
        public float SpecularIntensity { get; set; }

        public int SpecularShininess { get; set; }

        public MaterialBase()
        {
            AsDiffus = true;
            AsSpecular = true;

            DiffusIntensity = 0.85F;
            SpecularIntensity = 0.25F;

            SpecularShininess = 50;
        }

        public void setScene(Scene3D scene)
        {
            this.scene = scene;
        }

        public void SetBump(TextureBump Bump)
        {
            this.Bump = Bump;
        }

        protected void MakeBump(float u, float v, Base.V3 normal, V3 du, V3 dv)
        {
            float dhdu, dhdv;
            V3 newNormal;

            Bump.BumpValue(u, v, out dhdu, out dhdv);

            newNormal = normal + (((dhdu * normal) ^ dv) + (du ^ (dhdv * normal))) * Bump.Alpha;

            normal.x = newNormal.x;
            normal.y = newNormal.y;
            normal.z = newNormal.z;
            normal.Normalize();
        }

        public abstract Color GetColor(float u, float v, V3 normal, V3 du, V3 dv);
    }
}
